﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Client
{
    public partial class SnowBallForm : Form
    {
        Timer timerGrow;
        int size;
        int centerx;
        int centery;

        int maxx, maxy;

        public SnowBallForm()
        {
            timerGrow = new Timer();
            timerGrow.Interval = 50;   // 0.05s
            timerGrow.Tick += new EventHandler(timerGrow_Tick);

            size = 0;
            maxx = 216;
            maxy = 203;

            InitializeComponent();
        }

        void timerGrow_Tick(object sender, EventArgs e)
        {
            ++size;
            int x = (maxx/2) / 10 * size;
            int y = (maxy/2) / 10 * size;

            // Grow the window
            Bounds = new Rectangle( centerx - x, centery - y, x*2, y*2 );

            if (Size.Height > maxy)
            {
                // Too late !
                DialogResult = DialogResult.No;
            }
        }

        private void SnowBallForm_Shown(object sender, EventArgs e)
        {
            // Random position
            Random rd = new Random();
            centery = rd.Next(Screen.PrimaryScreen.Bounds.Bottom - maxy) + maxy/2;
            centerx = rd.Next(Screen.PrimaryScreen.Bounds.Right - maxx) + maxx/2;
            timerGrow.Start();
            timerGrow_Tick(null, null);
            WindowState = FormWindowState.Normal;
        }

        private void SnowBallForm_Click(object sender, EventArgs e)
        {
            // Good!
            DialogResult = DialogResult.Yes;
        }
    }
}
